# -*- coding: utf-8 -*-
"""
Created on Fri Oct  1 09:36:04 2021

@author: Administrator
"""

import sys
class Solution(object):
    def atoi(self,str):
        str = str.strip()
        if str == "":
            return 0
        i = 0
        sign = 1
        ret = 0
        length = len(str)
        MaxInt = (1 << 31)-1
        if str[i]== '+':
            i += 1
        elif str[i] == '-':
            i += 1
            sign = -1
        for i in range(i,length):
            if str[i] < '0' or str[i] > '9':
                break
            ret = ret * 10 + int(str[i])
            if ret > sys.maxsize:
                break
        ret *= sign
        if ret >= MaxInt:
            return MaxInt
        if ret < MaxInt * -1:
            return MaxInt * - 1 - 1
        return ret

if __name__ == "__main__":
    temp = Solution()
    string1 = "150"
    string2 = "32"
    print("输入："+string1)
    print("输出："+str(temp.atoi(string1)))
    print("输入："+string2)
    print("输出："+str(temp.atoi(string2)))